<!-- 游戏-->

<template>
  <el-dialog
    :model-value="dialogFormVisible"
    :destroy-on-close="true"
    title="游戏信息"
    width="600px"
    @close="emits('closeDialog')"
  >
    <el-form
      ref="dialogFormRef"
      :model="dialogForm"
      :rules="rules"
      :label-width="formLabelWidth"
    >
      <el-form-item label="英文名字" prop="name">
        <el-input v-model="dialogForm.name" />
      </el-form-item>
      <el-form-item label="中文名字" prop="name_zh">
        <el-input v-model="dialogForm.name_zh" />
      </el-form-item>
      <el-form-item label="印尼名字" prop="name_id">
        <el-input v-model="dialogForm.name_id" />
      </el-form-item>
      <el-form-item label="泰语名字" prop="name_th">
        <el-input v-model="dialogForm.name_th" />
      </el-form-item>
      <el-form-item label="三方游戏ID" prop="game_id">
        <el-input v-model="dialogForm.game_id" />
      </el-form-item>
      <el-form-item label="排序" prop="rank">
        <el-input v-model="dialogForm.rank" type="number"></el-input>
      </el-form-item>
      <el-form-item label="游戏分类" prop="category_id">
        <!-- <el-input v-model="dialogForm.category_id" type="number"></el-input> -->
        <el-select v-model="dialogForm.category_id" placeholder="游戏分类">
          <el-option
            v-for="item in gameCategoryList"
            :key="item.id"
            :label="item.id + '.' + item.name + '.' + item.parent_name"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="默认icon" :label-width="formLabelWidth">
        <el-upload
          :action="uploadimgUrl"
          :data="{ project_code: 'slotsgame' }"
          :show-file-list="false"
          :on-success="handleUploaderIconSuccess"
          :limit="1"
          :headers="TOKENT_HEADER"
          class="avatar-uploader"
        >
          <img
            v-if="dialogForm.icon"
            :src="dialogForm.icon_show"
            class="avatar"
          />
          <el-icon v-else class="avatar-uploader-icon">
            <Plus />
          </el-icon>
        </el-upload>
      </el-form-item>
      <el-form-item label="中文icon" :label-width="formLabelWidth">
        <el-upload
          :action="uploadimgUrl"
          :data="{ project_code: 'slotsgame' }"
          :show-file-list="false"
          :on-success="handleUploaderIconZHSuccess"
          :limit="1"
          :headers="TOKENT_HEADER"
          class="avatar-uploader"
        >
          <img
            v-if="dialogForm.icon_zh"
            :src="dialogForm.icon_zh_show"
            class="avatar"
          />
          <el-icon v-else class="avatar-uploader-icon">
            <Plus />
          </el-icon>
        </el-upload>
      </el-form-item>
      <el-form-item label="印尼icon" :label-width="formLabelWidth">
        <el-upload
          :action="uploadimgUrl"
          :data="{ project_code: 'slotsgame' }"
          :show-file-list="false"
          :on-success="handleUploaderIconIDSuccess"
          :limit="1"
          :headers="TOKENT_HEADER"
          class="avatar-uploader"
        >
          <img
            v-if="dialogForm.icon_id"
            :src="dialogForm.icon_id_show"
            class="avatar"
          />
          <el-icon v-else class="avatar-uploader-icon">
            <Plus />
          </el-icon>
        </el-upload>
      </el-form-item>
      <el-form-item label="泰语icon" :label-width="formLabelWidth">
        <el-upload
          :action="uploadimgUrl"
          :data="{ project_code: 'slotsgame' }"
          :show-file-list="false"
          :on-success="handleUploaderIconTHSuccess"
          :limit="1"
          :headers="TOKENT_HEADER"
          class="avatar-uploader"
        >
          <img
            v-if="dialogForm.icon_th"
            :src="dialogForm.icon_th_show"
            class="avatar"
          />
          <el-icon v-else class="avatar-uploader-icon">
            <Plus />
          </el-icon>
        </el-upload>
      </el-form-item>
      <el-form-item label="推荐英文图" :label-width="formLabelWidth">
        <el-upload
          :action="uploadimgUrl"
          :data="{ project_code: 'slotsgame' }"
          :show-file-list="false"
          :on-success="handleRecommendIconSuccess"
          :limit="1"
          :headers="TOKENT_HEADER"
          class="avatar-uploader"
        >
          <img
            v-if="dialogForm.recommend_icon"
            :src="dialogForm.recommend_icon_show"
            class="avatar1"
          />
          <el-icon v-else class="avatar-uploader-icon1">
            <Plus />
          </el-icon>
        </el-upload>
      </el-form-item>
      <el-form-item label="推荐中文图" :label-width="formLabelWidth">
        <el-upload
          :action="uploadimgUrl"
          :data="{ project_code: 'slotsgame' }"
          :show-file-list="false"
          :on-success="handleRecommendIconZHSuccess"
          :limit="1"
          :headers="TOKENT_HEADER"
          class="avatar-uploader"
        >
          <img
            v-if="dialogForm.recommend_icon_zh"
            :src="dialogForm.recommend_icon_zh_show"
            class="avatar1"
          />
          <el-icon v-else class="avatar-uploader-icon1">
            <Plus />
          </el-icon>
        </el-upload>
      </el-form-item>
      <el-form-item label="推荐印尼图" :label-width="formLabelWidth">
        <el-upload
          :action="uploadimgUrl"
          :data="{ project_code: 'slotsgame' }"
          :show-file-list="false"
          :on-success="handleRecommendIconIDSuccess"
          :limit="1"
          :headers="TOKENT_HEADER"
          class="avatar-uploader"
        >
          <img
            v-if="dialogForm.recommend_icon_id"
            :src="dialogForm.recommend_icon_id_show"
            class="avatar1"
          />
          <el-icon v-else class="avatar-uploader-icon1">
            <Plus />
          </el-icon>
        </el-upload>
      </el-form-item>
      <el-form-item label="推荐泰语图" :label-width="formLabelWidth">
        <el-upload
          :action="uploadimgUrl"
          :data="{ project_code: 'slotsgame' }"
          :show-file-list="false"
          :on-success="handleRecommendIconTHSuccess"
          :limit="1"
          :headers="TOKENT_HEADER"
          class="avatar-uploader"
        >
          <img
            v-if="dialogForm.recommend_icon_th"
            :src="dialogForm.recommend_icon_th_show"
            class="avatar1"
          />
          <el-icon v-else class="avatar-uploader-icon1">
            <Plus />
          </el-icon>
        </el-upload>
      </el-form-item>
      <el-form-item label="游戏厂商" prop="game_supplier">
        <el-select v-model="dialogForm.game_supplier" placeholder="游戏厂商">
          <el-option
            v-for="item in supplierList"
            :key="item"
            :label="item"
            :value="item"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="游戏提供商" prop="game_vendor">
        <el-input
          v-model="dialogForm.game_vendor"
          placeholder="厂商下的游戏提供商"
        ></el-input>
      </el-form-item>
      <el-form-item label="是否隐藏" prop="is_hide">
        <el-select v-model="dialogForm.is_hide" placeholder="是否隐藏">
          <el-option label="否" :value="0" />
          <el-option label="是" :value="1" />
        </el-select>
      </el-form-item>
      <el-form-item label="APP版本" prop="app_mark">
        <el-select v-model="dialogForm.app_mark" placeholder="APP版本">
          <el-option label="norm" value="norm"></el-option>
          <el-option label="cash" value="cash"> </el-option>
          <el-option label="all" value="all"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="id" style="display: none">
        <el-input v-model="dialogForm.id" disabled />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="emits('cancel')">取消</el-button>
        <el-button
          type="primary"
          @click="submit(dialogForm)"
          :loading="btnLoading"
          >提交</el-button
        >
      </span>
    </template>
  </el-dialog>
</template>
<script setup>
import { ref } from "vue";
import { uploadimgUrl } from "@/api/system/uploadimg";
import { TOKENT_HEADER } from "@/config/api-constant/system";
const dialogFormRef = ref(null);

defineProps({
  dialogFormVisible: {
    type: Boolean,
    default: false,
  },
  supplierList: {
    type: Array,
    default: [],
  },
  gameCategoryList: {
    type: Array,
    default: [],
  },
  dialogForm: {
    type: Object,
    default: {
      id: "",
      name: "",
      name_zh: "",
      name_id: "",
      name_th: "",
      game_id: "",
      rank: "",
      icon: "",
      icon_show: "",
      icon_zh: "",
      icon_zh_show: "",
      icon_id: "",
      icon_id_show: "",
      icon_th: "",
      icon_th_show: "",
      recommend_icon: "",
      recommend_icon_show: "",
      recommend_icon_zh: "",
      recommend_icon_zh_show: "",
      recommend_icon_id: "",
      recommend_icon_id_show: "",
      recommend_icon_th: "",
      recommend_icon_th_show: "",
      src: "",
      game_supplier: "",
      app_mark: "",
      is_hide: "",
      category_id: "",
      game_vendor: "",
    },
  },
  btnLoading: {
    type: Boolean,
    default: false,
  },
});
const emits = defineEmits([
  "closeDialog",
  "cancel",
  "submitForm",
  "handleUploaderImgRequest",
]);

const formLabelWidth = "150px";
// 校验
const rules = {
  name: [{ required: true, message: "请输入游戏名字", trigger: "blur" }],
  game_id: [{ required: true, message: "请输入三方游戏ID", trigger: "blur" }],
  category_id: [
    { required: true, message: "请输入游戏分类ID", trigger: "blue" },
  ],
  game_supplier: [
    { required: true, message: "请选择游戏厂商", trigger: "blur" },
  ],
  // game_vendor: [{ required: true, message: "请输入游戏提供商", trigger: "blur" }]
};

// 提交
const submit = (dialogForm) => {
  dialogFormRef.value
    .validate()
    .then(async () => {
      try {
        emits("submitForm", dialogForm);
      } catch (error) {
        console.log(error);
      }
    })
    .catch((error) => {
      console.log(error);
    });
};
const handleUploaderIconSuccess = (res) => {
  emits("handleUploaderImgRequest", res, "icon", "icon_show");
};
const handleUploaderIconZHSuccess = (res) => {
  emits("handleUploaderImgRequest", res, "icon_zh", "icon_zh_show");
};
const handleUploaderIconIDSuccess = (res) => {
  emits("handleUploaderImgRequest", res, "icon_id", "icon_id_show");
};
const handleUploaderIconTHSuccess = (res) => {
  emits("handleUploaderImgRequest", res, "icon_th", "icon_th_show");
};
const handleRecommendIconSuccess = (res) => {
  emits(
    "handleUploaderImgRequest",
    res,
    "recommend_icon",
    "recommend_icon_show"
  );
};
const handleRecommendIconZHSuccess = (res) => {
  emits(
    "handleUploaderImgRequest",
    res,
    "recommend_icon_zh",
    "recommend_icon_zh_show"
  );
};
const handleRecommendIconIDSuccess = (res) => {
  emits(
    "handleUploaderImgRequest",
    res,
    "recommend_icon_id",
    "recommend_icon_id_show"
  );
};
const handleRecommendIconTHSuccess = (res) => {
  emits(
    "handleUploaderImgRequest",
    res,
    "recommend_icon_th",
    "recommend_icon_th_show"
  );
};
</script>
